package ldh.im.fxgui.pane;

import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.control.Hyperlink;
import javafx.scene.text.TextFlow;
import ldh.im.dto.enums.MessageType;
import ldh.im.fxbase.data.pojo.ImMessage;
import ldh.im.fxbase.util.ParamUtil;
import ldh.im.fxbase.util.StageUtil;

public class UrlMessagePane extends BaseMessagePane {

    @Override
    public Node createPane(ImMessage message, boolean isReceive, boolean isRef) {
        TextFlow textFlow = new TextFlow();
        textFlow.setPadding(new Insets(10, 0, 10, 5));
        if (message.getMessageType() != MessageType.Url) {
            throw new RuntimeException("不支持这种消息类型" + message.getMessageType());
        }

        Hyperlink hyperlink = new Hyperlink();
        hyperlink.setWrapText(true);
        hyperlink.setText(message.getContent());
        hyperlink.setMaxWidth(ParamUtil.MESSAGE_WIDTH-10);

        if (isRef) {
            return hyperlink;
        }

        hyperlink.setOnAction(e->{
            StageUtil.getHostServices().showDocument(message.getContent());
        });
        textFlow.getChildren().add(hyperlink);

        buildPopup(textFlow, message);

        return textFlow;
    }
}
